package com.dongdongshop.Controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ConstantEnum;
import com.dongdongshop.pojo.TbContent;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.service.CategoryContentService;
import com.dongdongshop.service.ContentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("ContentController")
@Controller
public class ContentController {

    @Reference
    private ContentService contentService;
    @Reference
    private CategoryContentService categoryContentService;

    @RequestMapping("toContent")
    public String toContent(Model model){
        List<TbContentCategory> list = categoryContentService.selectAll();
        model.addAttribute("list",list);
        return "admin/content";
    }

    @RequestMapping("findAll")
    @ResponseBody
    public Result findAll(){
        List<TbContent> list = contentService.findAll();
        return Result.build(ConstantEnum.SUCCESS).setResult(list);
    }

    @RequestMapping("updateData")
    @ResponseBody
    public Result updateData(Long id){
        TbContent tbContent = contentService.selectById(id);
        return Result.build(ConstantEnum.SUCCESS).setResult(tbContent);
    }
    @RequestMapping("updateContent")
    @ResponseBody
    public Result updateContent(TbContent tbContent){
        contentService.updateContent(tbContent);
        return Result.build(ConstantEnum.SUCCESS);
    }

    @RequestMapping("insert")
    @ResponseBody
    public Result insertInfo(TbContent tbContent){
        contentService.insert(tbContent);
        return Result.build(ConstantEnum.SUCCESS);
    }

    @RequestMapping("deleteAll")
    @ResponseBody
    public Result deleteAll(Long[] ids){
        contentService.deleteAll(ids);
        return Result.build(ConstantEnum.SUCCESS);
    }
}
